<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Admin\Controller;
use Think\Controller;

class SearchController extends BaseController {
	/*
	 * 按标题搜索
	 */
	public function index(){
		$typeid = I('get.typeid',0);
		$key = iconv('gb2312','utf-8',$_GET['key']);
		if(!empty($key)){
			$article = D(C('TABLE_ARTICLE'));
			$where['title'] = array('LIKE',"%".$key."%");
			//dump($where);die;
			$result = $article->where($where)->order(array('id'=>'DESC'))->select();
//			$getdata = A('Index');
//			$getdata->gettypedata();
			$this->assign('articlelist',$result);
			$this->assign('page',1);
			$this->assign('empty',article_empty('article'));
			
			$this->display('Index/articlelist');
		}else{
			$this->error('搜索条件不满足','',1);
		}
	}
	
	/*
	 * 按华人码搜索
	 */
	public function indexma(){
		$key = iconv('gb2312','utf-8',$_GET['key']);
		if(!empty($key)){			
			$type = D(C('TABLE_TYPE'));
			if(session('userinfo')['type']){
				$where['typename'] = array('LIKE',"%".$key."%");
			}else{
				$where['typename'] = array('LIKE',"%".$key."%");
				$where['userid'] = session('userinfo')['id'];
			}
			$result = $type->order(array('id'=>'DESC'))->where($where)->select();
			$this->assign('list',$result);
			$this->assign('page',1);
			$this->assign('empty',article_empty('article'));

			//获取用户列表
			$u = A("User");
			$result = $u->userinfo();
			$this->assign('userlist', $result);
			$this->assign('getURL', iconv("GB2312", "UTF-8", getURL()));
			$this->display('Index/main');
		}else{
			$this->error('搜索条件不满足','',1);
		}
	}


}